package servlet;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import DAO.ScoreDao;
import DAO.StudentDao;
import DTO.Score;
import DTO.Student;

public class UpdateScoreServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String f=req.getParameter("f");
		boolean flag=false;
		ScoreDao sd=new ScoreDao();
		if(f==null){
		String sid=req.getParameter("sid");
	    String cid=req.getParameter("cid");
	    int cscore=Integer.parseInt(req.getParameter("cname"));
	   // int cscore=Integer.parseInt(req.getParameter("cscore"));
		Score s=new Score();
		s.setsId(sid);
		s.setcId(cid);
		s.setcScore(cscore);

		sd=new ScoreDao();
	       flag=sd.UpDataScore(s);
	    }else{//删除 
	     if(f.equals("delall")){//批量删除
	     String[] allsid=req.getParameterValues("allsid");
	     String[] temp=allsid[0].split(",");
	     for(String a : temp){
	      sd.DeleteScore(a);
	     }
	     flag=true;
	     }else{//只删除一条记录
	      String sid=req.getParameter("sid");
	        flag=sd.DeleteScore(sid);   
	     }
	   } 
	  Vector<Score> v=sd.fineAllScore();
	     HttpSession session=req.getSession();
	     session.setAttribute("allscore", v);
	  if(flag){
	      resp.sendRedirect(req.getContextPath()+"/admin/allscore.jsp");
	  }else{
	      resp.sendRedirect(req.getContextPath()+"/admin/error.jsp");
	  }
	   
	 }
	}
		
		
		
		
		/*flag =sd.UpDataScore(s);
		}else{
			if(f.equals("delall")){//批量删除
				String[] allsid =req.getParameterValues("allsid");
				String[] temp =allsid[0].split(",");
				for(String a :temp){
					sd.DeleteScore(a);
				}
				flag=true;
			}else{
			String cid=req.getParameter("cid");
			flag=sd.DeleteScore(cid);
		}
		}
		
	
		 Vector<Score> v =sd.fineAllScore();
	    	HttpSession session=req.getSession();
	    	session.setAttribute("allStu", v);
		
		
		//3
		if(flag){
			resp.sendRedirect(req.getContextPath()+"/admin/allStu.jsp");
		}else{
			resp.sendRedirect(req.getContextPath()+"/error.html");
		}
	}	
		
	}*/
	
	
	
	

